package com.chixing.day03.day03_Test;

public class Person {
    private String perName;  //姓名
    private int perAge;      //年龄
    private char perGender;   //性别
    private boolean perMarry; //是否结婚
    Person partner;  //配偶

    public Person() {

    }

    public Person(String perName, int perAge, char perGender, boolean perMarry) {
        this.perName = perName;
        this.perAge = perAge;
        this.perGender = perGender;
        this.perMarry = perMarry;

    }

    public String getPerName() {
        return perName;
    }

    public void setPerName(String perName) {
        this.perName = perName;
    }

    public int getPerAge() {
        return perAge;
    }

    public void setPerAge(int perAge) {
        this.perAge = perAge;
    }

    public char getPerGender() {
        return perGender;
    }

    public void setPerGender(char perGender) {
        this.perGender = perGender;
    }

    public boolean isPerMarry() {
        return perMarry;
    }

    public void setPerMarry(boolean perMarry) {
        this.perMarry = perMarry;
    }

    public boolean marry(Person p) {
        perMarry = true;
        if (perGender == p.perGender) {
            perMarry = false;
            System.out.println("同性不能结婚！！");
            return perMarry;
        }
        if ((perGender == '男' && perAge < 24) || (p.perGender == '男' && p.perAge < 24)) {
            perMarry = false;
            System.out.println("男性年龄不能小于24");
            return perMarry;
        }
        if ((perGender == '女' && perAge < 22) || (p.perGender == '女' && p.perAge < 22)) {
            perMarry = false;
            System.out.println("女性年龄不能小于22");
            return perMarry;
        }
        if (partner != null || p.partner != null) {
            perMarry = false;
            System.out.println("已婚的不能再结婚");
            return perMarry;
        }
        if (perMarry == true) {
            partner = p.partner;
            p.partner = partner;
            System.out.println("恭喜你们可以结婚！！");
            return perMarry;
        }
        return perMarry;

    }


}
